<?php

/*
 * Create by Indonesian Brain Solutions
 * E-mail : cs@mesinit.com
 * Programmer : sony@sonywibisono.com
 */
class Parts {
    var $id;
    var $part_name;
    var $part_type;

    function __construct($part_name,$part_type){
        $this->part_name=$part_name;
        $this->part_type=$part_type;
        $this->id=$this->insert();
    }
    function open($id){
        global $db;
        $sql="select * from parts where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->part_name=$part_name;
            $this->part_type=$part_type;

        }
    }

    function openAll(){
        $sql="select * from parts order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into parts values (null,'{$this->part_name}','{$this->part_type}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update parts set part_name='{$this->part_name}',
        part_type='{$this->part_type}' where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from parts where id=".$this->id;
        $db->query($sql);
    }

}
?>
